import { createRouter, createWebHistory } from "vue-router";
const routes = [
    {
        path: '/Login',
        name: 'Login',
        // 异步加载，打包时代码分割，性能优化
        component: () => import('@/components/Login.vue')
    },
    {
        path: '/',
        redirect: 'Login'
    },
    {
        path: '/Main',
        name: 'Main',
        component: () => import('@/components/Main.vue'),
        children: [
            {
                path: '/Main',
                redirect: '/YDADD' 
            },
            {
                path: '/DDGL',
                name: 'DDGL',
                component: () => import('@/components/DDGL.vue')
            },
            {
                path: '/Company',
                name: 'Company',
                component: () => import('@/components/Company.vue')
            },
            {
                path: '/Wb_meter',
                name: 'Wb_meter',
                component: () => import('@/components/Wb_meter.vue')
            },
            {
                path: '/Client',
                name: 'Client',
                component: () => import('@/components/Client.vue')
            },
            {
                path: '/ClientCreate',
                name: 'ClientCreate',
                component: () => import('@/components/ClientCreate.vue')
            },
            {
                path: '/Depart',
                name: "Depart",
                component: () => import('@/components/Depart.vue')
            },
            {
                path: '/JDGL',
                name: 'JDGL',
                component: () => import('@/components/JDGL.vue')
            },
            {
                path: '/XQ',
                name: 'XQ',
                component: () => import('@/components/XQ.vue')
            },
            {
                path: '/CYSGL',
                name: 'CYSGL',
                component: () => import('@/components/CYSGL.vue')
            },
            {
                path: "/Locus",
                name: "Locus",
                component: () => import('@/components/Locus.vue')
            },
            {
                path: '/Drivers',
                name: 'Drivers',
                component: () => import('@/components/Drivers.vue')
            },
            {
                path: '/DriversAdd',
                name: 'DriversAdd',
                component: () => import('@/components/DriversAdd.vue')
            },
            {
                path: '/Bill_ol',
                name: 'Bill_ol',
                component: () => import('@/components/Bill_ol.vue')
            },
            {
                path: '/Bill_xq',
                name: 'Bill_xq',
                component: () => import('@/components/Bill_xq.vue')
            },
            {
                path: '/CYSAdd',
                name: 'CYSAdd',
                component: () => import('@/components/CYSAdd')
            },
            {
                path: '/Vehicles',
                name: 'Vehicles',
                component: () => import('@/components/Vehicles')
            },
            {
                path: '/VehiclesEdit',
                name: 'VehiclesEdit',
                component: () => import('@/components/VehiclesEdit')
            },
            {
                path: '/HWGL',
                name: 'HWGL',
                component: () => import('@/components/HWGL')
            },
            {
                path: '/HWGLAdd',
                name: 'HWGLAdd',
                component: () => import('@/components/HWGLAdd')
            },
            {
                path: '/HWGLUpdate',
                name: 'HWGLUpdate',
                component: () => import('@/components/HWGLUpdate')
            },
            {
                path: '/CYSUpdate',
                name: 'CYSUpdate',
                component: () => import('@/components/CYSUpdate')
            },
            {
                path: '/CYSXQ',
                name: 'CYSXQ',
                component: () => import('@/components/CYSXQ')
            },
            {
                path: '/DDGLDD',
                name: 'DDGLDD',
                component: () => import('@/components/DDGLDD')
            },
            {
                path: '/KD',
                name: 'KD',
                component: () => import('@/components/KD')
            },
            {
                path: '/Address',
                name: 'Address',
                component: () => import('@/components/Address')
            },
            {
                path: '/AddressCreate',
                name: 'AddressCreate',
                component: () => import('@/components/AddressCreate')
            },
            {
                path: '/DepartEdit',
                name: 'DepartEdit',
                component: () => import('@/components/DepartEdit')
            },
            {
                path: '/Arrival',
                name: 'Arrival',
                component: () => import('@/components/Arrival')
            },
            {
                path: '/Signature_receipt',
                name: 'Signature_receipt',
                component: () => import('@/components/Signature_receipt')
            },
            {
                path: '/Employee',
                name: 'Employee',
                component: () => import('@/components/Employee')
            },
            {
                path: '/EmployeeEdit',
                name: 'EmployeeEdit',
                component: () => import('@/components/EmployeeEdit')
            },
            {
                path: '/Role',
                name: 'Role',
                component: () => import('@/components/Role')
            },
            {
                path: '/RoleEdit',
                name: 'RoleEdit',
                component: () => import('@/components/RoleEdit')
            },
            {
                path: '/Signature_xq',
                name: 'Signature_xq',
                component: () => import('@/components/Signature_xq')
            },
            {
                path: '/YDXQ',
                name: 'YDXQ',
                component: () => import('@/components/YDXQ')
            },
            {
                path: '/YDUpdate',
                name: 'YDUpdate',
                component: () => import('@/components/YDUpdate')

            },
            {
                path: '/YDAdd',
                name: 'YDAdd',
                component: () => import('@/components/YDAdd')

            },
            {
                path:'/YSGL',
                name:'YSGL',
                component:()=>import('@/components/YSGL.vue')
            },
            {
                path:'/Receipt_meter',
                name:'Receipt_meter',
                component:()=>import('@/components/Receipt_meter.vue')
            },
            {
                path:'/DDTJ',
                name:'DDTJ',
                component:()=>import('@/components/DDTJ.vue')
            },
            {
                path:'/SJYJTJ',
                name:'SJYJTJ',
                component:()=>import('@/components/SJYJTJ.vue')
            },
            {
                path:'/YCTJ',
                name:'YCTJ',
                component:()=>import('@/components/YCTJ.vue')
            },
            {
                path: '/Exception',
                name: 'Exception',
                component: () => import('@/components/Exception')
            },
            {
                path: '/ExceptionEdit',
                name: 'ExceptionEdit',
                component: () => import('@/components/ExceptionEdit')
            },
            {
                path: '/Receivable_meter',
                name: 'Receivable_meter',
                component: () => import('@/components/Receivable_meter')
            },
            {
                path: '/Receivable_meterUpdate',
                name: 'Receivable_meterUpdate',
                component: () => import('@/components/Receivable_meterUpdate')
            },
            {
                path: '/Receivable_meters',
                name: 'Receivable_meters',
                component: () => import('@/components/Receivable_meters')
            },
            {
                path: '/Payable_meter',
                name: 'Payable_meter',
                component: () => import('@/components/Payable_meter')
            },
            {
                path: '/Payable_meterUpdate',
                name: 'Payable_meterUpdate',
                component: () => import('@/components/Payable_meterUpdate')
            },
            {
                path: '/Payable_meters',
                name: 'Payable_meters',
                component: () => import('@/components/Payable_meters')
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(), // 路由模式：history模式
    routes: routes
})

// 配置全局前置守卫
router.beforeEach((to, from, next) => {
    // has token
    console.log(sessionStorage.getItem("token"));
    if (sessionStorage.getItem("token")) {
        console.log("1111");
        next();//放行
    } else if (to.path === "/Login") {

        next();//放行
    } else {
        alert("请填写正确的页面！！！")
        next({ path: '/Login' });
    }

    //next(); // 必须调用该方法来resolve这个钩子
});

export default router;